package ly.gupao.edu.java8.example3;

import ly.gupao.edu.java8.Apple;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;

/**
 * @author: liyang
 * @date：2018/9/4 0004
 * describe：
 */
public class Example_3_Function {

    public static void main(String[] args) {
        List<Apple> list = Arrays.asList(new Apple("red", 1.2), new Apple("green", 2.2));
        function(list, (Apple a) -> a.getColor());
    }

    public static <T,R> void function(List<T> list, Function<T, R> f){
        List<R> rList = new ArrayList<>();
        list.stream().forEach( e -> rList.add(f.apply(e)));
        System.out.println(rList);
    }

}
